package com.ken.elmssm.converter;


import com.ken.elmssm.bean.Role;
import com.ken.elmssm.common.ElmException;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;

/**
 * @author ken
 */
@Component("RoleListConverter")
public class RoleListConverter implements Converter<String[], List<Role>> {

    @Override
    public List<Role> convert(String[] source) {

        if (source != null && source.length > 0) {
            List<Role> list = new ArrayList<Role>();
            for (String roleId : source) {
                try {
                    list.add(new Role(Integer.valueOf(roleId), null));
                } catch (RuntimeException e) {
                    throw new ElmException("角色ID转换异常");
                }
            }
            return list;
        }
        return null;
    }

}
